//package com.touchfired.common.event.handler.impl;
//
//import com.touchfired.common.constants.ClientInfo;
//import com.touchfired.common.constants.EventCode;
//import com.touchfired.common.constants.RoomInfo;
//import com.touchfired.common.context.ServerContext;
//import com.touchfired.common.message.BaseMessage;
//import com.touchfired.common.message.transfer.MessageSender;
//import io.netty.channel.Channel;
//import io.netty.channel.ChannelHandlerContext;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.LinkedList;
//import java.util.List;
//import java.util.stream.Collectors;
//
///**
// * @Description 退出房间事件码处理器
// * @Author 幸佳俊
// */
//@Component
//public class EventCodeRoomQuitHandler extends BaseEventCodeHandler {
//
//    @Autowired
//    private ServerContext serverContext;
//
//    public EventCodeRoomQuitHandler() {
//        super(EventCode.ROOM_QUIT);
//    }
//
//    @Override
//    public EventCodeHandler doHandle(ChannelHandlerContext ctx, ClientInfo clientInfo, BaseMessage message) throws Exception {
//        String roomId = clientInfo.getRoomId();
//        RoomInfo roomInfo = serverContext.getRoomInfo(roomId);
//        if (roomInfo != null) {
//            LinkedList<String> roomClients = roomInfo.getRoomClients();
//            roomClients.removeIf(c -> clientInfo.getLongId().equals(c));
//            clientInfo.setRoomId(null);
//            serverContext.updateClientInfo(clientInfo);
//            if (roomClients.isEmpty()) {
//                serverContext.removeRoomInfo(roomId);
//            } else {
//                serverContext.updateRoomInfo(roomInfo);
//            }
//
//            // 当前房间的所有人
//            List<Channel> clientsChannel = roomClients.stream()
//                    .map(serverContext::getClientInfo)
//                    .map(ClientInfo::getChannel)
//                    .collect(Collectors.toList());
//            MessageSender.info(clientsChannel, message, clientInfo.getName() + "退出了房间。");
//        }
//        return eventHandle(ctx, clientInfo, message, EventCode.PADDING_JOINING);
//    }
//}
